package net.sxnic.ugr.permission.action;

import java.util.List;

import net.sxnic.comm.log.Log;
import net.sxnic.ugr.UgrActionSupport;
import net.sxnic.ugr.context.AppContext;
import net.sxnic.ugr.permission.Permission;
import net.sxnic.ugr.role.Role;

/**
 * @version $Revision$
 * @author 吕盛槐 create 2011-10-04
 */
@SuppressWarnings("serial")
public class Delete extends UgrActionSupport {
	
	private Role role;
	
 
	
	private List<Role> roles;
	

	public String execute() throws Exception {
		
		 try {						
			 
			 checkRoles(Permission.SYSTEM_ADMIN);
				Permission toDelete = this.authorizationManager.getPermissionById(id);
				// TODO 在删除一个角色前要首先取消角色对应的组和用户的引用
				 
//				toDelete.getResources().clear();				 
//				toDelete.getMenus().clear();
//				authorizationManager.updatePermission (toDelete);				
//				roles=authorizationManager.getRolesInPermission(toDelete);
//				 
//				//循环删除权限和角色的对应关系数据
//				for (int i=0;i<roles.size();i++)
//				{
//					role=roles.get(i);			 
//					role.getPermissions().remove(toDelete);			 
//					authorizationManager.updateRole(role);		 
//				}
//								 
				 authorizationManager.deletePermission (toDelete);
				 
				// 保存删除成功的信息
				 msg = "deleteSuccess";

				// 日志
				addLog(Log.LOG_OPERATION_DLETE, AppContext.getUserName(request)
						+ " delete permisssion sucess! permisssion id:" + id);
				
			} catch (Exception e) {
				e.printStackTrace();
			}
		

		return SUCCESS;
	}

}
